home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso / 0611 / mapi.dpr < prev    next >
Encoding:
Text File  |  1997-04-07  |  11.4 KB  |  320 lines

  1. {$A+,B-,D-,F-,G+,I-,K+,L-,N+,P+,Q-,R-,S+,T-,V+,W-,X+,Y-}
  2. {$M 16384,8192}
  3. library Mapi;
  4.  
  5. uses
  6.   WinTypes, Dialogs, WinProcs, SysUtils, IniFiles;
  7.  
  8. const
  9.    mapi_orig              = 0;             (* Recipient is message originator *)
  10.    mapi_to                = 1;             (* Recipient is a primary recipient *)
  11.    mapi_cc                = 2;             (* Recipient is a copy recipient *)
  12.    mapi_bcc               = 3;             (* Recipient is blind copy recipient *)
  13.  
  14.    mapi_ole               = $00000001;     (* Attachment is OLE *)
  15.    mapi_ole_static        = $00000002;     (* Use with mapi_ole, static object *)
  16.  
  17.    mapi_unread            = $00000001;
  18.    mapi_receipt_requested = $00000002;
  19.    mapi_sent              = $00000004;
  20.  
  21.    mapi_logon_ui          = $00000001;     (* Display logon UI *)
  22.    mapi_new_session       = $00000002;     (* Do not use default. *)
  23.    mapi_dialog            = $00000008;     (* Display a send note UI *)
  24.    mapi_unread_only       = $00000020;     (* Only unread messages *)
  25.    mapi_envelope_only     = $00000040;     (* Only header information *)
  26.    mapi_peek              = $00000080;     (* Do not mark as read. *)
  27.    mapi_guarantee_fifo    = $00000100;     (* use date order *)
  28.    mapi_body_as_file      = $00000200;
  29.    mapi_ab_nomodify       = $00000400;     (* Don't allow mods of AB entries *)
  30.    mapi_suppress_attach   = $00000800;     (* Header + body, no files *)
  31.    mapi_force_download    = $00001000;     (* Force download of new mail during MAPILogon *)
  32.  
  33.  
  34. type
  35.    tflags = longint;
  36.    ulong = longint;
  37.    lhandle = longint;
  38.  
  39.    plhandle = ^lhandle;
  40.    pulong = ^ulong;
  41.  
  42.    pMapiFileDesc = ^tMapiFileDesc;
  43.    tMapiFileDesc = record
  44.       ulReserved : longint;         (* Reserved for future use (must be 0) *)
  45.       flFlags : tflags;             (* Flags *)
  46.       nPosition : longint;          (* Character in text to be replaced by attachment *)
  47.       lpszPathName : pchar;         (* Full path name of attachment file *)
  48.       lpszFileName : pchar;         (* Original file name (optional) *)
  49.       lpFileType : pointer;         (* Attachment file type (optional) *)
  50.    end;
  51.  
  52.    pMapiRecipDesc = ^tMapiRecipDesc;
  53.    tMapiRecipDesc = record
  54.       ulReserved : longint;         (* Reserved for future use *)
  55.       ulRecipClass : longint;       (* Recipient class MAPI_TO, MAPI_CC, MAPI_BCC, MAPI_ORIG *)
  56.       lpszName : pchar;             (* Recipient name *)
  57.       lpszAddress : pchar;          (* Recipient address (optional) *)
  58.       ulEIDSize : longint;          (* Count in bytes of size of pEntryID *)
  59.       lpEntryID : pointer;          (* System-specific recipient reference *)
  60.    end;
  61.  
  62.    pMapiMessage = ^tMapiMessage;
  63.    tMapiMessage = record
  64.       ulReserved : longint;               (* Reserved for future use (must be 0) *)
  65.       lpszSubject : pchar;                (* Message Subject *)
  66.       lpszNoteText : pchar;               (* Message Text *)
  67.       lpszMessageType : pchar;            (* Message Class *)
  68.       lpszDateReceived : pchar;           (* In YYYY/MM/DD HH:MM format *)
  69.       lpszConversationID : pchar;         (* Conversation thread ID *)
  70.       flFlags : tflags;                   (* Unread,return receipt *)
  71.       lpOriginator : pMapiRecipDesc;      (* Originator descriptor *)
  72.       nRecipCount : ulong;                (* Number of recipients *)
  73.       lpRecips : pMapiRecipDesc;          (* Recipient descriptors *)
  74.       nFileCount : ulong;                 (* # of file attachments *)
  75.       lpFiles : pMapiFileDesc;            (* Attachment descriptors *)
  76.    end;
  77.  
  78. const                                                 (* error codes *)
  79.    success_success                 = 0;
  80.    mapi_user_abort                 = 1;
  81.    mapi_e_failure                  = 2;
  82.    mapi_e_login_failure            = 3;
  83.    mapi_e_disk_full                = 4;
  84.    mapi_e_insufficient_memory      = 5;
  85.    mapi_e_access_denied            = 6;
  86.    mapi_e_too_many_sessions        = 8;
  87.    mapi_e_too_many_files           = 9;
  88.    mapi_e_too_many_recipients      = 10;
  89.    mapi_e_attachment_not_found     = 11;
  90.    mapi_e_attachment_open_failure  = 12;
  91.    mapi_e_attachment_write_failure = 13;
  92.    mapi_e_unknown_recipient        = 14;
  93.    mapi_e_bad_reciptype            = 15;
  94.    mapi_e_no_messages              = 16;
  95.    mapi_e_invalid_message          = 17;
  96.    mapi_e_text_too_large           = 18;
  97.    mapi_e_invalid_session          = 19;
  98.    mapi_e_type_not_supported       = 20;
  99.    mapi_e_ambiguous_recipient      = 21;
  100.    mapi_e_message_in_use           = 22;
  101.    mapi_e_network_failure          = 23;
  102.    mapi_e_invalid_editfields       = 24;
  103.    mapi_e_invalid_recips           = 25;
  104.    mapi_e_not_supported            = 26;
  105.  
  106. var
  107.   INIFile: TINIFile;
  108.   INIFileName: String;
  109.   MailProgram: String;
  110.   ToSyntax: String;
  111.   CmdLine: array[0..256] of char;
  112.   OldExitProc: Pointer;
  113.   DebugLevel: Integer;
  114.   ProgHandle: THandle;
  115.  
  116.  
  117. function Substitute(BigString, OldSubString, NewSubString: String): String;
  118. var Position: Byte;
  119. begin
  120.   Position := Pos(OldSubString, BigString);
  121.   if Position > 0 then begin
  122.     Delete(BigString, Position, Length(OldSubString));
  123.     Insert(NewSubString, BigString, Position);
  124.   end;
  125.   Result := BigString;
  126. end;
  127.  
  128. function MAPILogon (ulUIParam : ulong;
  129.                     lpszName, lpszPassword : pchar;
  130.                     flFlags : tflags;
  131.                     ulReserved : ulong;
  132.                     lplhSession : plhandle) : ulong; export;
  133. begin
  134.   StrPCopy(CmdLine, MailProgram);
  135.   if DebugLevel > 1 then
  136.     ShowMessage('Logon: Invoking ' + StrPas(CmdLine));
  137.   ProgHandle := WinExec(CmdLine, SW_SHOWMINIMIZED);
  138.   if ProgHandle < HINSTANCE_ERROR then begin
  139.     ShowMessage('Error ' + IntToStr(ProgHandle) + ' executing '
  140.       + StrPas(CmdLine));
  141.     Result := mapi_e_failure;
  142.   end else
  143.     Result := success_success;
  144. end;
  145.  
  146. function MAPILogoff (lhSession : lhandle;
  147.                      ulUIParam : ulong;
  148.                      flFlags : tflags;
  149.                      ulReserved : ulong) : ulong; export;
  150. begin
  151.   Result := success_success;
  152. end;
  153.  
  154. function MAPISendMail (lhSession : lhandle;
  155.                        ulUIParam : ulong;
  156.                        lpMessage : pMapiMessage;
  157.                        flFlags : tflags;
  158.                        ulReserved : ulong) : ulong; export;
  159. begin
  160.   if lpMessage^.nRecipCount = 0 then
  161.     StrPCopy(CmdLine, MailProgram)
  162.   else
  163.     StrPCopy(CmdLine, MailProgram
  164.       + Substitute(ToSyntax,'%s',StrPas(lpMessage^.lpRecips^.lpszName)));
  165.   if DebugLevel > 1 then
  166.     ShowMessage('Send Mail: Invoking ' + StrPas(CmdLine));
  167.   ProgHandle := WinExec(CmdLine, SW_SHOW);
  168.   if ProgHandle < HINSTANCE_ERROR then begin
  169.     ShowMessage('Error ' + IntToStr(ProgHandle) + ' executing '
  170.       + StrPas(CmdLine));
  171.     Result := mapi_e_failure;
  172.   end else
  173.     Result := success_success;
  174. end;
  175.  
  176. function MAPISendDocuments (ulUIParam : ulong;
  177.                             lpszDelimChar : pchar;
  178.                             lpszFilePaths : pchar;
  179.                             lpszFileNames : pchar;
  180.                             ulReserved : ulong) : ulong; export;
  181. begin
  182.   ShowMessage('Send documents not supported.');
  183.   Result := mapi_e_not_supported;
  184. end;
  185.  
  186. function MAPIFindNext (lhSession : lhandle;
  187.                        ulUIParam : ulong;
  188.                        lpszMessageType, lpszSeedMessageID : pchar;
  189.                        flFlags : tflags;
  190.                        ulReserved : ulong;
  191.                        lpszMessageID : pchar) : ulong; export;
  192. begin
  193.   if DebugLevel > 0 then
  194.     ShowMessage('Find next not supported');
  195.   Result := mapi_e_not_supported;
  196. end;
  197.  
  198. function MAPIReadMail (lhSession : lhandle;
  199.                        ulUIParam : ulong;
  200.                        lpszMessageID : pchar;
  201.                        flFlags : tflags;
  202.                        ulReserved : ulong;
  203.                        lppMessageOut : pMapiMessage) : ulong; export;
  204. begin
  205.   if DebugLevel > 0 then
  206.     ShowMessage('Read mail not supported');
  207.   Result := mapi_e_not_supported;
  208. end;
  209.  
  210. function MAPISaveMail (lhSession : lhandle;
  211.                        ulUIParam : ulong;
  212.                        pMessage : pMapiMessage;
  213.                        flFlags : tflags;
  214.                        ulReserved : ulong;
  215.                        lpszMessageID : pchar) : ulong; export;
  216. begin
  217.   if DebugLevel > 0 then
  218.     ShowMessage('Save mail not supported');
  219.   Result := mapi_e_not_supported;
  220. end;
  221.  
  222. function MAPIDeleteMail (lhSession : lhandle;
  223.                          ulUIParam : ulong;
  224.                          lpszMessageID : pchar;
  225.                          flFlags : tflags;
  226.                          ulReserved : ulong) : ulong; export;
  227. begin
  228.   if DebugLevel > 0 then
  229.     ShowMessage('Delete mail not supported');
  230.   Result := mapi_e_not_supported;
  231. end;
  232.  
  233. function MAPIFreeBuffer (pv : pointer) : ulong; export;
  234. begin
  235.   if DebugLevel > 0 then
  236.     ShowMessage('Free buffer not supported');
  237.   Result := mapi_e_not_supported;
  238. end;
  239.  
  240. function MAPIAddress (lhSession : lhandle;
  241.                       ulUIParam : ulong;
  242.                       plszCaption : pchar;
  243.                       nEditFields : ulong;
  244.                       lpszLabels : pchar;
  245.                       nRecips : ulong;
  246.                       lpRecips : pMapiRecipDesc;
  247.                       flFlags : tflags;
  248.                       ulReserved : ulong;
  249.                       lpnNewRecips : pUlong;
  250.                       lppNewRecips : pMapiRecipDesc) : ulong; export;
  251. begin
  252.   if DebugLevel > 0 then
  253.     ShowMessage('Address not supported');
  254.   Result := mapi_e_not_supported;
  255. end;
  256.  
  257. function MAPIDetails (lhSession : lhandle;
  258.                       ulUIParam : lhandle;
  259.                       lpRecip : pMapiRecipDesc;
  260.                       flFlags : tflags;
  261.                       ulReserved : ulong) : ulong; export;
  262. begin
  263.   if DebugLevel > 0 then
  264.     ShowMessage('Details not supported');
  265.   Result := mapi_e_not_supported;
  266. end;
  267.  
  268. function MAPIResolveName (lhSession : lhandle;
  269.                           ulUIParam : ulong;
  270.                           lpszName : pchar;
  271.                           flFlags : tflags;
  272.                           ulReserved : ulong;
  273.                           lppRecip : pMapiRecipDesc) : ulong; export;
  274. begin
  275.   if DebugLevel > 0 then
  276.     ShowMessage('Resolve name not supported');
  277.   Result := mapi_e_not_supported;
  278. end;
  279.  
  280. procedure MyExitProc; far;
  281. begin
  282.   INIFile.Free;
  283.   ExitProc := OldExitProc;
  284. end;
  285.  
  286. {$R *.RES}
  287.  
  288. exports
  289.   MAPILogon index 1,
  290.   MAPILogoff index 2,
  291.   MAPISendMail index 3,
  292.   MAPISendDocuments index 4,
  293.   MAPIFindNext index 5,
  294.   MAPIReadMail index 6,
  295.   MAPISaveMail index 7,
  296.   MAPIDeleteMail index 8,
  297.   MAPIFreeBuffer index 9,
  298.   MAPIAddress index 10,
  299.   MAPIDetails index 11,
  300.   MAPIResolveName index 12;
  301.  
  302. begin
  303.   INIFileName := Substitute(ParamStr(0), '.DLL', '.INI');
  304.   INIFile := TINIFile.Create(INIFileName);
  305.   DebugLevel := INIFile.ReadInteger('Options','Debug Level',1);
  306.   if DebugLevel > 1 then
  307.     ShowMessage('Config read from ' + INIFileName);
  308.   OldExitProc := ExitProc;
  309.   ExitProc := @MyExitProc;
  310.   MailProgram := INIFile.ReadString('Mailer','Program','');
  311.   if MailProgram = '' then
  312.     ShowMessage('No definition for Program in Mailer section of ' + INIFileName);
  313.   ToSyntax := ' ' + INIFile.ReadString('Mailer','ToSyntax','');
  314.   if ToSyntax = '' then begin
  315.     if DebugLevel > 0 then
  316.       ShowMessage('No definition for To Syntax in Mailer section of ' + INIFileName)
  317.   end else
  318.     ToSyntax := ' ' + ToSyntax;
  319. end.
  320.